//
//  HJDPesonalCenterViewController.m
//  JYHospital
//
//  Created by 胡金东 on 16/6/7.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDPesonalCenterViewController.h"
#import "HJDHealthViewController.h"

#import "HJDSetViewController.h"
#import "HJDSetDateViewController.h"
#import "HJDCalculateDateViewController.h"
#import "HJDEVersionViewController.h"
#import "HJDNavigationController.h"
#import "HJDCTimeViewController.h"
#import "HJDUserInfoViewController.h"
#import "HJDLoginViewController.h"


#import <MobileCoreServices/MobileCoreServices.h>
#import <QuartzCore/QuartzCore.h>



@interface HJDPesonalCenterViewController ()<UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@property (nonatomic,strong) UITableView * tableView;

@property (nonatomic,strong) UIImageView * imageView;

//@property(nonatomic, strong) NSData *fileData;






@end

@implementation HJDPesonalCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    [self setUpBtn];
    [self setUpTable];
}
-(void)setUpBtn{
    
    UIButton *resiBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 20, 250,90 )];
    [resiBtn addTarget:self action:@selector(resiBtn) forControlEvents:UIControlEventTouchUpInside];
    [resiBtn setBackgroundColor:[UIColor redColor]];
    [self.view addSubview:resiBtn];
    
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 5, 80, 80)];
    [self.imageView setRadius:self.imageView.height/2 borderWith:0 borderColor:nil];
    
    //    加载首先访问本地沙盒是否存在相关图片
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"currentImage.png"];
    UIImage *savedImage = [UIImage imageWithContentsOfFile:fullPath];
    
    if (!savedImage)
    {
        //默认头像
        self.imageView.image = [UIImage imageNamed:@"头像"];
    }
    else
    {
        self.imageView.image = savedImage;
     }
    

    [resiBtn addSubview:self.imageView];
    
    
    
   
}



-(void)resiBtn
{
    HJDUserInfoViewController *userInfo = [[HJDUserInfoViewController alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:userInfo];
    
    [self presentViewController:nav animated:YES completion:nil];
    HJDLog(@"点击了");
}


-(void)setUpTable
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 120,260 , 700)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;

    [self.view addSubview:self.tableView];
    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0){
        return 4;
    }else {
        return 2;
   
    }
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    if (indexPath.section == 0) {
        if (indexPath.row ==0) {
            cell.imageView.image = [UIImage imageNamed:@"孕期档案"];
            cell.textLabel.text = @"孕期档案";
        }else if (indexPath.row ==1){
            cell.imageView.image = [UIImage imageNamed:@"我的论坛"];
            cell.textLabel.text = @"我的论坛";
        }else if (indexPath.row == 2) {
            cell.imageView.image = [UIImage imageNamed:@"会员专区"];
            cell.textLabel.text = @"会员专区";
        }else {
            cell.imageView.image = [UIImage imageNamed:@"产检记录"];
            cell.textLabel.text = @"产检记录";
        }

        
    }else if (indexPath.section == 1){
        
        if (indexPath.row == 0) {
            cell.imageView.image = [UIImage imageNamed:@"设置"];
            cell.textLabel.text = @"设置";
        }else{
            cell.imageView.image = [UIImage imageNamed:@"版本更新"];
            cell.textLabel.text = @"版本更新";
        }
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
//{
//    return 30;
//}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            HJDSetDateViewController *setDate = [[HJDSetDateViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:setDate];
           
            [self presentViewController:nav animated:YES completion:nil];
//            NSLog(@"%ld",indexPath.row);
        }else{
            HJDLoginViewController *calculate = [[HJDLoginViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:calculate];
            
            [self presentViewController:nav animated:YES completion:nil];
           
        }
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            HJDHealthViewController *health = [[HJDHealthViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:health];
            
            [self presentViewController:nav animated:YES completion:nil];
        }else{
            HJDCTimeViewController *cTime = [[HJDCTimeViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:cTime];
            
            [self presentViewController:nav animated:YES completion:nil];
        }
        
    }else if (indexPath.section == 2){
        if (indexPath.row ==0) {
            HJDSetViewController *set = [[HJDSetViewController alloc]init];
            
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:set];
            
            [self presentViewController:nav animated:YES completion:nil];

           
        }else{
            HJDEVersionViewController *version = [[HJDEVersionViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:version];
            
            [self presentViewController:nav animated:YES completion:nil];
                   }
        
    }
    
}


@end
